﻿@{
    ViewBag.Title = "Home Page";
}
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

<div class="row">
    <div class="col-md-4">
    </div>
    <div class="col-md-4">
        <div>
            <input type="button" class="btn-img btn-regist" id="moniclick" style="cursor:pointer" value="模拟事件" tabindex="8">
            <input type="button" class="btn-img btn-regist" id="RefreshQrcode" style="cursor:pointer" value="刷新二维码" tabindex="8">
            <img id="imgQrCode" src="" width="250" height="250" />
        </div>
    </div>
    <div class="col-md-4">
    </div>
</div>
<script>
    var scene_id = "";
    $(function () {
        $('#RefreshQrcode').click(function () { 
            $.post('/Home/CreateWeiXinQrcode', null, function (data) { 
                if (data.success) {
                    //alert(data.Data);
                    $('#imgQrCode').attr('src', "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + data.Data.ticket);
                    var strMessage = "使用微信扫描二维码即可快速注册！";
                    alert(strMessage);
                    scene_id = data.Data.scene_id;
                    setTimeout("QrWxConnect()", 6000);
                }
                else { 
                    alert("生成二维码失败！");
                }
            });
        });
        $('#moniclick').click(function () {
            $.post('/WeiXin/Index', null, function (data) {
            });
        });
    });

    function QrWxConnect() {
        $.post('/Home/QrWxConnect', { ttt: new Date().getTime(), token: scene_id, src: "", flag:2}, function (data) {
            if (data.success) { 
                if (data.status == 0) {
                    setTimeout("QrWxConnect()", 6000);//再次请求
                } else if (data.status == 1) {
                    //成功
                    window.location.href = "http://kiy.cn/"; 
                } 
            }
            else {
                alert("生成二维码失败！");
            }
        }); 
    }

</script> 